package offer.easy.math;

import java.util.Arrays;

public class JumpFloorJust1or2 {

    //青蛙一次可以跳[1,2]步，则在青蛙跳到最后一次之前可以在[n-2,n-1]的台阶
    //设青蛙跳N级台阶的跳法共有f(n)种
    //f(n) = f(n-1) + f(n-2)，推出式子斐波那契数列

    public static int JumpFloorI(int n) {
        if (n <= 3) {
            return n;
        } else {
            return (JumpFloorI(n-1) + JumpFloorI(n-2));
        }
    }

    public static int[] JumpFloorII(int n) {
        int[] arr = new int[n+1];
        arr[0] = 0;
        arr[1] = 1;
        arr[2] = 2;
        arr[3] = 3;
        for (int i = 3; i <= n; i++) {
            arr[i] = arr[i-2] + arr[i-1];
        }
        return arr;
    }

    public static void main(String[] args) {
        int num = JumpFloorI(5);
        int[] arr = JumpFloorII(7);
        System.out.println(num);
        System.out.println(Arrays.toString(arr));
    }
}
